package com.poseidon.web.aspect;

import java.util.Arrays;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;


/***
 *
 * @author wujf 拦截所有控制器的返回，记录响应报文
 */
@Aspect
@Configuration
public class QmttAspect {
    private static final Logger log = LoggerFactory.getLogger(QmttAspect.class);

    public QmttAspect() {
    }

    // 不能拦截@RequestMapping，这样会导致swagger无法使用
    // @Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    @Pointcut("execution(public * com.poseidon.support.uap.server.Controller..*.*(..))")
    public void pointCutMethod() {
    }

    // 声明环绕通知
    @Around("pointCutMethod()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        String controller = pjp.getTarget().getClass().getSimpleName();
        String method = pjp.getSignature().getName();
        String args = Arrays.toString(pjp.getArgs());
        Object ret = pjp.proceed();
        log.info("响应数据:{}", ret);
        return ret;
    }
}
